package com.ww.byteBuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.nio.charset.Charset;

/**
 * @ClassName:
 * @author:
 * @Description:
 * @Date
 **/
public class ByteBuf04 {
    public static void main(String[] args) {
        Charset charset = Charset.forName("UTF-8");
        ByteBuf buf = Unpooled.copiedBuffer("Netty in action rocks.", charset);
        //打印第一个字符N
        System.out.println((char) buf.readByte());
        int readerIndex = buf.readerIndex();
        int writerIndex = buf.writerIndex();
        //将字符？追加到缓冲区
        buf.writeByte((byte) '?');
        assert readerIndex == buf.readerIndex();
        // 因为writeByte移动了writerIndex，所以断言会成功
        assert writerIndex != buf.writerIndex();
        System.out.println(buf.maxCapacity());
    }
}
